﻿using Common;
using IBLL;
using Microsoft.AspNetCore.Mvc;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Unmanned_MSUI.Areas.Admin.Filters;

namespace Unmanned_MSUI.Areas.Admin.Controllers
{
    [Area("Admin")]
    [MyFilter]
    public class UserBalanceInfoController : Controller
    {
        private IUserBalanceInfoBLL _userBalanceInfoBLL;
        public UserBalanceInfoController(
            IUserBalanceInfoBLL userBalanceInfoBLL
            )
        {
            _userBalanceInfoBLL = userBalanceInfoBLL;
        }

        public IActionResult ListView()
        {
            return View();
        }
        public IActionResult BalanceRecordView()
        {
            return View();
        }
        

        #region 获取用户余额列表的方法(GetUserBalanceInfo)
        [HttpGet]
        public IActionResult GetUserBalanceInfo(int page, int limit, string userId, string account, string userName)
        {
            //声明返回对象
            ReturnResult result = new ReturnResult();
            int count;
            //调用BLL的获取用户方法
            var list = _userBalanceInfoBLL.GetUserBalanceInfo(page, limit, userId, account,  userName, out count);
            //返回值
            result.Code = 0;
            result.IsSuccess = true;
            result.Msg = "获取用户余额列表成功";
            result.Count = count;
            result.Data = list;
            //返回结果
            return Json(result);
        }
        #endregion

        #region 获取余额记录列表的方法(GetBalanceRecordInfo)
        [HttpGet]
        public IActionResult GetBalanceRecordInfo(int page, int limit, string id)
        {
            //声明返回对象
            ReturnResult result = new ReturnResult();
            int count;
            //调用BLL的获取用户方法
            var list = _userBalanceInfoBLL.GetBalanceRecordInfo(page, limit, id, out count);
            //返回值
            result.Code = 0;
            result.IsSuccess = true;
            result.Msg = "获取用户余额记录列表成功";
            result.Count = count;
            result.Data = list;
            //返回结果
            return Json(result);
        }
        #endregion

        #region 根据id获取用户余额详情(GetUserBalanceInfoById)
        /// <summary>
        /// 根据id获取用户余额详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUserBalanceInfoById(string id)
        {
            //实例化返回对象
            ReturnResult result = new ReturnResult();
            //判断id是否为空
            if (string.IsNullOrWhiteSpace(id))
            {
                result.Msg = "id不能为空";
                return Json(result);
            }
            //根据id查询数据信息，并判断是否为空
            UserBalanceInfo userBalanceInfo = _userBalanceInfoBLL.GetUserBalanceInfoById(id);
            if (userBalanceInfo == null)
            {
                result.Msg = "未获取用户余额信息";
            }
            else
            {
                result.Code = 200;
                result.Msg = "查询成功!";

                result.Data = new
                {
                    userBalanceInfo,//返回耗材类别信息
                };

            }
            return Json(result);//返回结果
        }
        #endregion
    }
}
